#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int maxArea(vector<int>& height) {
        int max = 0;
        int i = 0, j = height.size() - 1;
        while (i < j) {
            int capacity = min(height[i], height[j]) * (j - i);
            if (max < capacity)
                max = capacity;
            
            if (height[i] < height[j])
                i++;
            else
                j--;
        }
        
        return max;
    }
};

// input: 1,8,6,2,5,4,8,3,7
// ouput: 49
void test01() {
    cout << "test01:" << endl;

    vector<int> input = {1,8,6,2,5,4,8,3,7};
    Solution obj;
    cout << "max:" << obj.maxArea(input) << endl;
}

// input: 1,1
// ouput: 1
void test02() {
    cout << "test02:" << endl;

    vector<int> input = {1,1};
    Solution obj;
    cout << "max:" << obj.maxArea(input) << endl;
}

// input: 1,0
// ouput: 0
void test03() {
    cout << "test03:" << endl;

    vector<int> input = {1,0};
    Solution obj;
    cout << "max:" << obj.maxArea(input) << endl;
}

// input: 1,2
// ouput: 1
void test04() {
    cout << "test04:" << endl;

    vector<int> input = {1,2};
    Solution obj;
    cout << "max:" << obj.maxArea(input) << endl;
}

// input [8,7,2,1]
// output 7
void test05() {
    cout << "test05:" << endl;

    vector<int> input = {8,7,2,1};
    Solution obj;
    cout << "max:" << obj.maxArea(input) << endl;
}


int main() {
    test01();
    test02();
    test03();
    test04();
    test05();
    return 0;
}
